(function($){
    $.fn.extend({
    	/*添加任意个标签*/
        addTag:function(Tag,TagLens){
		 	this.each(function(index,object){
				for(var i=0;i<TagLens;i++){
					this.appendChild(document.createElement(Tag));
				};
			});
			return this.children();
		},
		/*文件路径*/
		src:function(url){
			this.each(function(index,object){
				this.src=url;			
			});
			return this;
		},
		/*选项卡-点击*/
		tab:function(target,act){
			this.each(function(index,object){
				$(this).click(function(){
					$(this).addClass(act).siblings().removeClass(act);
					$(target).eq(index).show().siblings().hide();
				});
			});
		},
		/*选项卡-hover*/
		xxk:function(target,act){
			this.each(function(index,object){
				$(this).hover(function(){
					$(this).addClass(act).siblings().removeClass(act);
					$(target).eq(index).show().siblings().hide();
				});
			});
		},
		/*伸缩菜单*/
		flex:function(){
			this.each(function(index,object){
				var minHeight=$(this).find('p').height()+2;
				var maxHeight=minHeight+$(this).find('ol').height();
				$(this).click(function(){
					$(this).animate({
							'height':maxHeight,
					},300).siblings().animate({
							'height':minHeight,
					},300)
				});
			});
		},
		/*复制到粘贴板*/
		copy:function(name) {
			this.each(function(index,object){
				$(this).click(function(){
					$(name).select();
           			document.execCommand("Copy");
           			alert('已复制，可贴粘。');
				})
			});
        },
        /*清除*/
        clear:function(name){
        	this.each(function(){
        		$(this).click(function(){
        			$(name).val("");
        		});
        	});
        },
        /*按键*/
		key:function(key,fn){
			this.each(function(index,object){
				object.onkeydown=function(ev){
					var oEvent=ev||event;
			 		if(!key){
			 			console.log(oEvent.keyCode);					
			 		}
					else if(oEvent.keyCode==key){
						fn();
					};
				};
			});
			return this;
		},
		/*拖拉*/
		drag:function(callbak){
			this.each(function(index,object){
				$(object).mousedown(function(e){
					var oEvent = e || event;
					var disX = oEvent.pageX-object.offsetLeft;
					var disY = oEvent.pageY-object.offsetTop;
					$(document).mousemove(function(e){
					    var oEvent = e || event;
					    var l = oEvent.pageX - disX;
					    var t = oEvent.pageY - disY;
					    $(object).each(function(){
					    	var r = $(object).parent().width() - $(object).width();
					    	var d = $(object).parent().height() - $(object).height();
								if(l < 0){
									l = 0;
								} else if (l > r){
									l = r;
								}
								if(t < 0){
									t = 0;
								} else if (t > d){
									t= d;
								}
							callbak(l,t);
					    })
					})
					$(document).mouseup(function (){
					    $(this).unbind("mousemove");
					}); 
				});
			});
		},
		/*无缝滚动*/
		marquee:function(speed){
			this.each(function(index,object){
				var oUl=$(this).find('ul')[0];
				var aLi=oUl.getElementsByTagName('li');
				var timer=setInterval(move,30);
				oUl.innerHTML=oUl.innerHTML + oUl.innerHTML ;
				oUl.style.width=aLi[0].offsetWidth*aLi.length+'px';
				function move(){
					var l=oUl.offsetLeft
						w=-oUl.offsetWidth/2
					if(l<w){
						oUl.style.left='0';
					}
					if(l>0){
						oUl.style.left=w+'px';
					}
					oUl.style.left=oUl.offsetLeft+speed+'px';
				}
				$(this).hover(function(){
					clearInterval(timer);
				},function(){
					timer=setInterval(move,30);
				})
			});
		},
		/*显示时间*/
		showTime:function(){
			this.each(function(index,object){
			function a(){
				var oDate=new Date(),
				y=oDate.getFullYear(),
				m=oDate.getMonth()+1,
				d=oDate.getDate(),
				w=oDate.getDay(),
				wk=["日","一","二","三","四","五","六"],
				h=oDate.getHours(),
				mi=oDate.getMinutes(),
				s=oDate.getSeconds();
				h=b(h);
				mi=b(mi);
				s=b(s);
				function b(t){
					if(t<10){t='0'+t} return t;
				}
				var c=y+"/"+m+"/"+d+"星期"+wk[w],d=+h+":"+mi+":"+s;
				object.innerHTML=d;
			}
				a();
				setInterval(a,1000);
			})
		},
    });
})(jQuery);